package com.ygo.feihua.util;
import java.util.*;
import net.lingala.zip4j.core.*;
import net.lingala.zip4j.exception.*;
import net.lingala.zip4j.model.*;

public class CardImageUtil
{
	private ZipFile zipFile;
	public  final static int TYPE_KM=0;
	public final static int TYPE_PATH=1;
	
	public CardImageUtil(String zipPath){
		try{
			zipFile = new ZipFile(zipPath);
		}catch (ZipException e){
			
		}
	}
	
	public  String DelCardImage(int type,String s){
		if(zipFile!=null){
		try{
			switch(type){
				case TYPE_KM:
					s="pics/"+s+".jpg";
					break;
				case TYPE_PATH:
				
					break;
				}		
				//删除指定文件
				zipFile.removeFile(s);
				return "";
			}catch (ZipException e){
			return ""+e;
			}
		}else{
			return "压缩包读取失败";
		}
	}
	public  List<String> CIQuery(String km)
	{
		List<String> ls=new ArrayList<String>();
		if (zipFile != null){
			try{
				List fileHeaderList = zipFile.getFileHeaders();
				for (int i = 0; i < fileHeaderList.size(); i++){  
					FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);  
					String name=fileHeader.getFileName();
					if (name.indexOf(km) != -1){
						ls.add(name);
					}

					/*
					 System.out.println("****File Details for: " + fileHeader.getFileName() + "*****");  
					 System.out.println("Name: " + fileHeader.getFileName());  
					 System.out.println("Compressed Size: " + fileHeader.getCompressedSize());  
					 System.out.println("Uncompressed Size: " + fileHeader.getUncompressedSize());  
					 System.out.println("CRC: " + fileHeader.getCrc32());  
					 System.out.println("************************************************************");  */
				}  
			}
			catch (ZipException e){
				
			}  
		}
		return ls;
	}

	
}
